import { Component} from '@angular/core';
import { NavController, NavParams,AlertController } from 'ionic-angular';
import { NativeService }    from '../../service/NativeService'
import { ServicePage }      from './service/service';
import { AboutPage }        from './about/about';
import { BankPage }         from './bank/bank';
import { MessagePage }      from './message/message';
import { ProblemPage }      from './problem/problem';
import { PasswordPage }     from './password/password';
import { UserInfoPage }     from './user-info/user-info';
import { BettingPage }      from './betting/betting';

import { LoginPage }        from '../account/login/login';
import { UserService}       from '../../service/userService';

@Component({
  selector: 'page-me',
  templateUrl: 'me.html',
})
export class MePage {

  private dataSource:any;
  private isLoing:boolean = false;
  constructor(public navCtrl: NavController,
              public alertCtrl:AlertController,
              public navParams: NavParams,
              public user:UserService,
              public nat:NativeService) {

    this.initData();
  }

  ionViewWillEnter(){

  }

  initData(){

    this.dataSource = [
      [
        {
        icon:'./assets/imgs/message.png',
        name:'站内消息'
      },{
        icon:'./assets/imgs/bank.png',
        name:'银行卡'
      },{
        icon:'./assets/imgs/password.png',
        name:'修改密码'
      },{
        icon:'./assets/imgs/betting.png',
        name:'投注记录'
      }
    ],[
      {
        icon:'./assets/imgs/qa.png',
        name:'常见问题'
      },{
        icon:'./assets/imgs/serve.png',
        name:'联系客服'
      },{
        icon:'./assets/imgs/about.png',
        name:'关于我们'
      },{
        icon:'./assets/imgs/share.png',
        name:'分享应用'
      }
    ]];

  }

  loginAction(){
    let alert = this.alertCtrl.create({
      title: '是否退出当前账号',
      buttons: [{
        text:'取消',
        role:'cancel',
        handler: () =>{
          console.log('取消');
        }
      },{
        text:'确定',
        handler: () =>{
          this.user.isLogin = false;
        }
      }],
    });
    alert.present();
  }


  pushUserInfo(){
    if (!this.user.isLogin){
      this.navCtrl.push(LoginPage);
    }else {
      this.navCtrl.push(UserInfoPage);
    }
  }

  clickAction(i,j){

    if( i == 0){
      if (!this.user.isLogin){
        this.navCtrl.push(LoginPage);
        return;
      }
      if (j == 0){
        this.navCtrl.push(MessagePage);
      }else if(j == 1){
        this.navCtrl.push(BankPage);
      }else if(j == 2){
        this.navCtrl.push(PasswordPage);
      }else if(j == 3){
        this.navCtrl.push(BettingPage);
      }
    }else {
      if (j == 0){
        this.navCtrl.push(ProblemPage);
      }else if(j == 1){
        this.navCtrl.push(ServicePage);
      }else if(j == 2){
        this.navCtrl.push(AboutPage);
      }else if(j == 3){
        this.nat.showToast("分享应用");

      }
    }
  }

}
